import pandas_datareader.data as web
import datetime
import requests
import json


def mi():
    df_stockload = web.DataReader("1810.HK", "yahoo", datetime.date.today())

    # print(df_stockload.head())

    # print(df_stockload.index)
    # print(df_stockload.High)
    # print(df_stockload.Low)
    # print(df_stockload.Open)
    # print(df_stockload.Close)

    # print(df_stockload.Volume)

    # print(df_stockload.Volume.iloc[0])

    # print(datetime.date.today())

    s = round(df_stockload.Close.iloc[0],2)
    return s

def post_feishu(day,s):
    # 你复制的webhook地址
    url = "https://open.feishu.cn/open-apis/bot/v2/hook/xxxx"
    payload_message = {
        "msg_type":"interactive",
        "card":{
            "config":{
                "wide_screen_mode":True
            },
            "elements":[
                {
                    "tag":"markdown",
                    "content": str(day) + "\n" + str(s)
                }
            ],
            "header":{
                "template":"blue",
                "title":{
                    "content":"🎉 雷总的新韭菜",
                    "tag":"plain_text"
                }
            }
        }
    }

    headers = {
        'Content-Type': 'application/json'
    }

    response = requests.request("POST", url, headers=headers, data=json.dumps(payload_message))

    # print(response.text)
    return response.text

if __name__ == '__main__':
    message = mi()
    post_feishu(datetime.date.today(),message)
    